import request from '@/utils/request'

// 获取录像列表
export function getRecordings(params) {
  return request({
    url: '/recordings',
    method: 'get',
    params
  })
}

// 开始录像
export function startRecording(channelId, recordingConfig) {
  return request({
    url: `/channels/${channelId}/recording/start`,
    method: 'post',
    data: recordingConfig
  })
}

// 停止录像
export function stopRecording(channelId) {
  return request({
    url: `/channels/${channelId}/recording/stop`,
    method: 'post'
  })
}

// 获取录像状态
export function getRecordingStatus(channelId) {
  return request({
    url: `/channels/${channelId}/recording/status`,
    method: 'get'
  })
}

// 下载录像
export function downloadRecording(recordingId) {
  return request({
    url: `/recordings/${recordingId}/download`,
    method: 'get',
    responseType: 'blob'
  })
}

// 删除录像
export function deleteRecording(recordingId) {
  return request({
    url: `/recordings/${recordingId}`,
    method: 'delete'
  })
}

// 批量删除录像
export function batchDeleteRecordings(recordingIds) {
  return request({
    url: '/recordings/batch/delete',
    method: 'post',
    data: { recordingIds }
  })
}

// 批量下载录像
export function batchDownloadRecordings(recordingIds) {
  return request({
    url: '/recordings/batch/download',
    method: 'post',
    data: { recordingIds },
    responseType: 'blob'
  })
}

// 获取录像详情
export function getRecordingDetail(recordingId) {
  return request({
    url: `/recordings/${recordingId}`,
    method: 'get'
  })
}

// 获取录像播放URL
export function getRecordingPlayUrl(recordingId) {
  return request({
    url: `/recordings/${recordingId}/play-url`,
    method: 'get'
  })
}

// 搜索录像
export function searchRecordings(searchParams) {
  return request({
    url: '/recordings/search',
    method: 'post',
    data: searchParams
  })
}

// 获取录像配置
export function getRecordingConfig(channelId) {
  return request({
    url: `/channels/${channelId}/recording/config`,
    method: 'get'
  })
}

// 设置录像配置
export function setRecordingConfig(channelId, config) {
  return request({
    url: `/channels/${channelId}/recording/config`,
    method: 'put',
    data: config
  })
}

// 获取录像统计信息
export function getRecordingStats(params) {
  return request({
    url: '/recordings/stats',
    method: 'get',
    params
  })
}

// 批量开始录像
export function batchStartRecording(channelIds, recordingConfig) {
  return request({
    url: '/recordings/batch/start',
    method: 'post',
    data: {
      channelIds,
      recordingConfig
    }
  })
}

// 批量停止录像
export function batchStopRecording(channelIds) {
  return request({
    url: '/recordings/batch/stop',
    method: 'post',
    data: { channelIds }
  })
}

// 批量获取录像状态
export function batchGetRecordingStatus(channelIds) {
  return request({
    url: '/recordings/batch/status',
    method: 'post',
    data: { channelIds }
  })
}

// 批量设置录像配置
export function batchSetRecordingConfig(channelIds, config) {
  return request({
    url: '/recordings/batch/config',
    method: 'put',
    data: {
      channelIds,
      config
    }
  })
}